package cn.wolfcode.p2p.mgrsite.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wolfcode.p2p.base.exception.DisplayableException;
import cn.wolfcode.p2p.base.query.RealAuthQueryObject;
import cn.wolfcode.p2p.base.service.IRealAuthService;
import cn.wolfcode.p2p.base.util.JSONResult;

/**
 * 后台实名认证审核控制器
 * 
 * @author wolfcode
 *
 */
@Controller
public class RealAuthController {

	@Autowired
	private IRealAuthService realAuthService;

	/**
	 * 实名认证审核
	 */
	@RequestMapping("realAuth_audit")
	@ResponseBody
	public JSONResult audit(Long id, int state, String remark) {
		JSONResult result = new JSONResult();
		try {
			this.realAuthService.audit(id,state,remark);
		} catch (DisplayableException ex) {
			result = new JSONResult(false, ex.getMessage());
		} catch (Exception e) {
			// 把错误信息记录到服务器中日志文件中,方便排查问题.
			result = new JSONResult(false, "系统异常,请联系管理员!");
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 实名认证列表
	 * 
	 * @param qo
	 * @param model
	 * @return
	 */
	@RequestMapping("realAuth")
	public String realAuthList(@ModelAttribute("qo") RealAuthQueryObject qo, Model model) {
		model.addAttribute("pageResult", this.realAuthService.query(qo));
		return "realAuth/list";
	}

}
